<template>
  <div>
    <!-- 用户容量信息 -->
    <div style="float:left;">
      <span style="margin-right: 5px">可用：{{userStorage.avail}}</span>
      <span style="margin-right: 5px">已用：{{userStorage.used}}</span>
      <span style="margin-right: 5px">总量：{{userStorage.capacity}}</span>
    </div>
    <!-- 文件管理器 -->
    <div id="elfinder" div style="clear: left;text-align: left">
    </div>
  </div>
</template>

<script>
  import Cookies from "js-cookie";
  import {baseUrl} from '@/utils/global'

  export default {
    name: "UserFile",
    data() {
      return {
        userId: null,
        userStorage: {
          capacity: null,
          avail: null,
          used: null
        }
      }
    },
    mounted() {
      this.userId = sessionStorage.getItem("userId");
      // 当前用户容量
      this.$api.userStorage.findByUserId({userId: this.userId}).then(res => {
        Object.assign(this.userStorage, res.data);
      });
      // 浏览器高度
      let clientHeight = 0;
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
      }
      clientHeight -= 150;

      // 当前用户文件管理
      let data = {
            url: '',
            lang: 'zh_CN',
            customData: {
              userId: this.userId
            },
            customHeaders: {
              'token': Cookies.get('token')
            },
            commands: [
              'archive', 'back', 'chmod', 'colwidth', 'copy', 'cut', 'download', 'duplicate', 'edit', 'extract',
              'forward', 'fullscreen', 'getfile', 'help', 'home', 'info', 'mkdir', 'mkfile', 'netmount', 'netunmount',
              'open', 'opendir', 'paste', 'places', 'quicklook', 'reload', 'rename', 'resize', 'restore', 'rm',
              'search', 'sort', 'up', 'upload', 'view', 'zipdl'
            ],
            height: clientHeight <= 0 ? 400 : clientHeight
          }
      ;
      data.url = baseUrl + '/filemanager/connector';
      $('#elfinder').elfinder(data);
    }

  }
</script>

<style>
</style>
